var app = angular.module('app');
app.factory('clockValuesService', [function () {
    var clockValuesService = {};
    clockValuesService.values = [];
    for (var i = 0; i < 48; i++) {
        var time = i / 2.0;
        var hour = Math.floor(time);
        var minuteLabel = '00';
        if (hour != time) {
            // half hour
            minuteLabel = '30';
        }
        var timeLabel = hour + ':' + minuteLabel;
        var hourDate = new Date(0, 0, 0, hour, parseInt(minuteLabel));
        clockValuesService.values.push({id: i + '', label: timeLabel, value: hourDate});
    }

    clockValuesService.getValue = function (id) {
        for (var i in clockValuesService.values) {
            if (id == clockValuesService.values[i].id) {
                return clockValuesService.values[i].value;
            }
        }
        return null;
    };

    clockValuesService.getId = function (date) {
        if (!date) {
            return -1;
        }
        for (var i in clockValuesService.values) {
            if (date.getHours() == clockValuesService.values[i].value.getHours() &&
                date.getMinutes() == clockValuesService.values[i].value.getMinutes()) {
                return i;
            }
        }
        return -1;
    };

    return clockValuesService;
}]);